gv_fake_camera: fix spurious 100 ms stall in the frame pacing loop - #1089
Open
rperez45 wants to merge 1 commit into
Open
gv_fake_camera: fix spurious 100 ms stall in the frame pacing loop#1089rperez45 wants to merge 1 commit into
rperez45 wants to merge 1 commit into
Conversation
timeout_ms is computed as (next_timestamp_us - g_get_real_time ()) / 1000LL. next_timestamp_us is a guint64, so when the frame deadline has already passed by the time this line runs (scheduler preemption, or a control packet handled right at the deadline), the subtraction underflows to a huge unsigned value and the following clamp turns it into a 100 ms poll timeout instead of 0. Because the fake camera schedules frames on wall-clock-aligned slots (arv_fake_camera_get_sleep_time_for_next_frame), every such stall silently drops ~100 ms worth of frame slots, which are never made up. Streaming a 640x224 Mono16 fake camera at 527 fps, this fired every few seconds and cost ~2 % of the effective frame rate (irregular ~102 ms inter-frame gaps while the median gap stayed exactly at the nominal period). With the signed cast the stalls disappear and the measured rate matches the requested frame rate exactly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
In
ArvGvFakeCamera's_threadloop, the poll timeout is computed as:next_timestamp_usis aguint64. If the frame deadline has already passed by the time this line executes — a scheduler preemption between computing the deadline and polling, or a GVCP control packet (e.g. a heartbeat) handled right at the deadline — the subtraction underflows to a huge unsigned value, and thetimeout_ms > 100clamp just below turns it into a spurious 100 ms poll instead of 0.Because frames are scheduled on wall-clock-aligned slots (
arv_fake_camera_get_sleep_time_for_next_framereturnsperiod - now % period), the ~100 ms of missed frame slots are silently skipped, never made up.Observed effect
Streaming a 640×224 Mono16 fake camera at 527 fps (GigE Vision hyperspectral camera emulation), the fake camera consistently delivered ~2 % under the requested rate. Receiver-side inter-frame timing showed the signature: the median gap was exactly the nominal period (1897 µs), but irregular ~102 ms stalls appeared every few seconds:
Fix
Cast to signed before subtracting, so an expired deadline yields a negative value and takes the existing
timeout_ms < 0 → 0path:After the fix, same probe:
and a 4-stream 60 s run measured 527.1–527.2 fps on all four fake cameras with zero stalls.
🤖 Generated with Claude Code